<template>
  <SimpleList :list="tableStore.tables" @click="handleClick" @add="addTable"></SimpleList>
</template>

<script lang="ts" setup>
import SimpleList from '../utils/SimpleList.vue';
import { useConfigTableStore } from '@/stores/config/configTableStore';
import { useTablePageStore } from '@/stores/config/tablePageStore';
import { toRaw } from 'vue';
let tableStore = useConfigTableStore()
let pageStore = useTablePageStore()
let handleClick = (id: number) => {
  pageStore.selectedId = id
}
const electron = require("electron")
let saveTableData = function () {
  console.log('Save table data:');
    // electron.ipcRenderer.invoke('saveTableStore', toRaw(tableStore.$state));
    electron.ipcRenderer.invoke('saveStoreToLocal', toRaw(tableStore.$state))
      .then((result: any) => console.log('Save result:', result))
      .catch((error: any) => console.error('Save error:', error));
}
let addTable = () => {
  tableStore.addTable()
  saveTableData()
}
</script>